(function(){
    $.ajax({
        url:'http://chst.vip:1234/api/getbrandtitle'
    })
    .then(res=>{
        render(res.result)
        // console.log(res);
    })

    function render(data = []){
        data = [...data]
        let page =""
        data.forEach(item=>{
            // console.log(item);
            page +=`
            <div class="panle-group-10" brandtitleid = "${item.brandTitleId}">
            <div>
                ${item.brandTitle}
            </div>
            <span>&#9660;</span>
        </div>
        <div class="panle-group-10-10">
        </div>
            `
        })
        $('#panle-group').html(page)
    }
    //点击事件
    $("#panle-group").on("click",".panle-group-10",function(){
        //获取属性值
        let titleid = $(this).attr('brandtitleid')
        console.log(titleid);

       fetch(`http://chst.vip:1234/api/getbrand?brandtitleid=${titleid}`)
       .then((body)=>body.json())
       .then((res)=>{
        // console.log(res);
        let newData =[...res.result]
        console.log(newData);
        let page1 =""
        let count = 0
        newData.forEach(item=>{
            // 遍历加一
            count++
            // console.log(count++);
            page1 +=`
            <div class="panle-group-10-10-10" brandid = "${item.brandTitleId}" title = "${item.brandName}">
                    <i>${count}</i>
                    <span>${item.brandName}</span>
                    <p>${item.brandInfo}</p>
                </div>
            `
        })
        // console.log($(this).index);
        $('.panle-group-10-10').eq($(this).index('.panle-group-10')).slideToggle().html(page1)
        // console.log($('.panle-group-10-10').eq($(this).index('.panle-group-10')).slideToggle().html(page1));
       })
       $('.panle-group-10-10').on('click', '.panle-group-10-10-10', function () {
        let brandid = $(this).attr('brandid')
        console.log(brandid);
        let title = $(this).attr('title')
        location.href = `../pages/brand.html?title=${title}&brandtitleid=${brandid}`
    })
    })
})()